package com.weilf.zookeeper.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.ZooKeeper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;



/**
 * 测试类
 * @author weil-f
 * @date 2021/2/7 8:29
 */
@Slf4j
public class ZkConfigTest {

	private ZooKeeper zk ;

	@Before
	public void getZk(){
		try {
			zk = ZkUtils.instance();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@After
	public void close(){
		try {
			zk.close();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}


	@Test
	public void testConfig(){
		WatcherCallBack watcherCallBack = new WatcherCallBack();
		MyConfig myConfig = new MyConfig();
		watcherCallBack.setZk(zk);
		watcherCallBack.setMyConfig(myConfig);
		watcherCallBack.awit();
		while (true){
			if("".equals(myConfig.getConfig())){
				log.info("配置文件丢了");
				watcherCallBack.awit();
			}else {
				log.info("配置文件获取到的数据为===>{}",myConfig.getConfig());
			}
			try {
				Thread.sleep(1000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
